package com.seocoo.worker.user.login.model;

import android.text.TextUtils;

import com.sfh.lib.mvvm.BaseViewModel;
import com.sfh.lib.ui.DialogBuilder;

public class LoginModel extends BaseViewModel {
    public void login(ReqLogin reqLogin) {

        this.execute(false, reqLogin, result -> {
            if (result.success()) {
                setValue("onLoginSuccess");
            } else {
                showDialogToast(result.getMsg());
            }
        });
    }

    public void sendSMS(ReqSMS req) {

        this.execute(false, req, result -> {
            if (result.success()) {
                showToast("验证码发送成功！");
                setValue("onSendCodeSuccess");
            } else if (TextUtils.equals("500", result.getCode())) {
                DialogBuilder builder = new DialogBuilder();
                builder.setMessage(result.getMsg());
                builder.setOKTextListener("立即注册", (dialog, which) -> {
                    dialog.dismiss();
                    setValue("onGotoRegisterUI");
                });
                showDialog(builder);
            } else {
                showDialogToast(result.getMsg());
            }
        });
    }
}
